<?php echo $this->Html->script("jquery.ui.accordion"); ?>
<?php echo $this->Html->script("tiny_mce/tiny_mce"); ?>
<?php echo $this->Html->script("user_globel"); ?>

<div id="content">
	<?php echo $this->Form->input("ticketId", array('value' => $ticket['Ticket']['id'], 'type' => 'hidden')); ?>
  <!--  start page-heading -->
  <div id="page-heading">
      <h1><?php echo __('Ticket Detail'); ?></h1>
  </div>
	<!-- end page-heading -->
  <?php  
         $DAY = Setting::get_option('DAY');
         $HOUR = Setting::get_option('HOUR');
         $MINUTE = Setting::get_option('MINUTE');
         $SECOND = Setting::get_option('SECOND');
  ?>
	<table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
    	<tr>
      		<th rowspan="3" class="sized">
              <?php echo $this->Html->image('/images/shared/side_shadowleft.jpg', array('width' => '20', 'height' => '300', 'alt' => '')); ?>
          </th>
      		<th class="topleft"></th>
      		<td id="tbl-border-top">&nbsp;</td>
      		<th class="topright"></th>
      		<th rowspan="3" class="sized">
              <?php echo $this->Html->image('/images/shared/side_shadowright.jpg', array('width' => '20', 'height' => '300', 'alt' => '')); ?>
          </th>
    	</tr>
    	<tr>
		      <td id="tbl-border-left"></td>
		      <td>
		<!--  start content-table-inner ...................................................................... START -->
		          <div id="content-table-inner">
		
			<!--  start table-content  -->
          			<div id="table-content">
           	       <div id="page-heading1"></div>   
                   <table border="0" width="100%" cellpadding="0" cellspacing="0" id="product-table">
                       <tr>
                           <td class="table-header-repeat line-left"><span>Ticket</span></td> 
                           <th class="table-header-repeat line-left">&nbsp;</th>
                           <th class="table-header-repeat line-left">&nbsp;</th> 
                           <th class="table-header-repeat line-left">&nbsp;</th>
                       </tr>
                       <tr>
                           <th>Name</th> 
                           <td><?php echo $ticket['Ticket']['name']; //ucfirst($ticket['Ticket']['first_name']).' '.ucfirst($ticket['Ticket']['last_name']); ?></td>
                           <th>Ticket Id</th> 
                           <td><?php echo "#".$ticket['Ticket']['key']; ?></td>
                       </tr>
                       <tr>
                           <th>Type</th> 
                           <td><?php echo $ticket['Ticket']['type']; ?></td>
                           <th>Email</th>
                           <td><?php echo $ticket['Ticket']['email']; ?></td>
                       </tr>
                       <tr>
                           <th>Country</th>
                           <td><?php echo Country::get_name($ticket['Ticket']['country_id']); ?></td>
                           <th>City</th> 
                           <td><?php echo City::get_name($ticket['Ticket']['city_id']); ?></td>
                       </tr>
                       <tr>
                           <th>Phone</th> 
                           <td><?php echo $ticket['Ticket']['mobile']; ?></td>
                           <th>SLA</th>
                           <td><?php echo $this->Slashow->makeSla($ticket, $DAY, $HOUR, $MINUTE, $SECOND); ?></td>
                       </tr>
                       <tr>
                          <th>Status</th>
                          <td><?php echo $ticket['Ticket']['status']; ?>
                             &nbsp;   
                            <?php echo $this->Html->link('Change Status', array('controller' => 'tickets', 'action' => 'change_status', $ticket['Ticket']['id']), array('class' => 'change_status')); ?>
                          </td>
                          <th>&nbsp;</th>
                          <td>&nbsp;</td>
                       </tr>
                       <tr>
                          <th>Created</th> 
                          <td><?php echo date('d/m/Y h:i A', strtotime($ticket['Ticket']['created'])); ?></td>
                          <th>Last Updated</th> 
                          <td><?php echo date('d/m/Y h:i A', strtotime($ticket['Ticket']['modified'])); ?></td>
                       </tr>
                       <tr>
                          <th>Subject</th> 
                          <td colspan="3"><?php echo $ticket['Ticket']['subject']; ?></td>
                       </tr>
                       <tr>
                          <th>Description</th> 
                          <td colspan="3"><?php echo $ticket['Ticket']['description']; ?></td>
                       </tr>
                  </table>
                  
          <!-- Change Status History  -->
                  <table border="0" width="100%" cellpadding="0" cellspacing="0" class="ticketReason" id="reason-table">
                       <tr><th colspan="4" class="table-header-repeat line-left">Changed Status History</th></tr>
                       <tr class="reason-heading">
                            <td>Changed Status</td>
                            <td>Previous Status</td>
                            <td>Date</td>
                            <td>Reason</td>
                       </tr>
                       <?php 
                          foreach($ticket['TicketReason'] as $value):
                       ?>
                       <tr>
                            <td><?php echo $value['status']; ?></td>
                            <td><?php echo $value['previous']; ?></td>
                            <td><?php echo date('d/m/Y h:i A', strtotime($value['created'])); ?></td>
                            <td><?php echo $value['reason']; ?></td>
                       </tr>
                       <?php 
                          endforeach;
                       ?>
                  </table>
     <!--     Message Container Start -->
                  <table width="100%" cellspacing="0" cellpadding="0" border="0" id="message-table" class="ticketMessages">
                       <tr>
                           <th class="table-header-repeat line-left">Ticket Messages</th>
                           <th class="table-header-repeat line-left">
                            <span title="Send Email" class="button">
                                <!--<a id="mcNewMessage" class="oBtn oBtnPrimary" onclick="return false;" href="#">Send Email</a>-->
                              <?php 
                                  echo $this->Js->link("Send Email", 
                                                      array(
                                                          'controller' => 'tickets', 
                                                          'action' => 'reply',
                                                          $ticket['Ticket']['id']
                                                      ), 
                                                      array(
                                                          'update' => '#send_email_form',
                                                          'htmlAttributes' => array(
                                                              'id' => 'mcNewMessage',
                                                              'class' => 'oBtn oBtnPrimary'
                                                          ),
                                                          'success' => '$("#send_email_message").show();',
                                                          'escape' => false
                                                      )
                                                  );  
                              ?>
                            </span>
                       </th>
                       </tr>
                       <tr id="send_email_message" style="display:none;">
                            <td colspan="2" id="send_email_form"> This is too bad</td>
                       </tr>
                       <tr>
                           <td colspan="2" class="message-main_div"> 
                            <div id="accordion">
              
                      <?php  
                          
                          foreach($messages as $message):    
                            if($message['Header']['TicketMessage']['from'] == 'Admin'){
                                $background = "#57E964";
                            }else{
                                $background = "#F88017";
                            } 
                       ?>
                                  	<h3 style = "">
                                        <a href="#">
                                            <?php echo $message['Header']['TicketMessage']['subject']; ?>
                                            <span style="margin-left:50px;float:right;">
                                              From: <?php echo $message['Header']['TicketMessage']['name']; ?>&nbsp;&nbsp;&nbsp;
                                              Received: <?php echo date('d/m/Y h:i A', strtotime($message['Header']['TicketMessage']['created'])); ?> 
                                            </span>
                                        </a>
                                    </h3>
                                  	<div>
                                          <?php 
                                              $j = 0;
                                              foreach($message['Content'] as $content){ 
                                            ?>
                                          <div class="content-main">
                                              <div class="header-message">
                                                  <div style="width: 300px;float: left;"> From : <?php echo $content['TicketMessage']['name']; ?></div>
                                                  <div style="width: 300px;float: left;"> Received : <?php echo date('d/m/Y h:i A', strtotime($content['TicketMessage']['created'])); ?></div>
                                                  <div style="width: 470px;float: left; text-align: right;">
                                                        <?php $msgID = $content['TicketMessage']['id']; ?>
                                                        <?php 
                                                            echo $this->Js->link("Reply", 
                                                                                array(
                                                                                    'controller' => 'tickets', 
                                                                                    'action' => 'reply',
                                                                                    $content['TicketMessage']['ticket_id'],
                                                                                    $content['TicketMessage']['id']
                                                                                ), 
                                                                                array(
                                                                                    'update' => "#reply_area_{$msgID}",
                                                                                    'htmlAttributes' => array(
                                                                                        'class' => 'reply-button'
                                                                                    )
                                                                                )
                                                                            );  
                                                        ?>
                                                        <span title="Forward" class="forward-button" id="<?php echo $content['TicketMessage']['id']; ?>"> Forward </span>
                                                        <?php echo $this->Html->link("delete", array('controller' => 'tickets', 'action' => 'delete', 'admin' => true, $content['TicketMessage']['id']), array('class' => 'del_button', 'title' => 'Delete'), 'Are you sure, you want to delete this message?' ); ?>
                                                        <!--<span title="Reply" class="reply-button" id="reply-<?php echo $content['TicketMessage']['ticket_id'].'-'.$content['TicketMessage']['id']; ?>"> Reply </span>-->
                                                  </div>
                                              </div>
                                              <div class="reply-box" id="reply_area_<?php echo $content['TicketMessage']['id']; ?>"></div>
                                              <div class="content-title"> Content :</div>
                                              <div class="content-message">
                                                    <?php echo $content['TicketMessage']['content']; ?>
                                              </div>
                                          </div>
                                            <?php
                                                $j++; 
                                                }
                                              ?>
                                  	</div>
              
              
                              <?php 
                                  
                                  endforeach; 
                              ?>
                                  </div>
                            </td>
                          </tr>
                  </table>

		<!--  end trainer-table................................... --> 
			
      </div>
			<!--  end content-table  -->
		

			<div class="clear"></div>
		 
		</div>
		<!--  end content-table-inner ............................................END  -->
		</td>
		<td id="tbl-border-right"></td>
	</tr>
	<tr>
		<th class="sized bottomleft"></th>
		<td id="tbl-border-bottom">&nbsp;</td>
		<th class="sized bottomright"></th>
	</tr>
	</table>
	<div class="clear">&nbsp;</div>

</div>
<div id="dialog">
    <div>Email
    <?php echo $this->Form->input('email', array('id' => 'forward_mail', 'label' => false, 'div' => false, 'class' => 'inp-form')); ?></div>
</div>

<?php
    echo $this->Js->writeBuffer();
?>
<style>
#TicketKey {
    border: medium none;
}
#TicketCreateOnsiteSesionForm{
    display: none;
}
.ticketReason{
    margin-bottom: 30px;
}
.reason-heading{
    background: none repeat scroll 0 0 #999999;
    color: #FFFFFF;
    font-size: 14px;
    font-weight: bold;
    height: 30px;
}    
#reason-table th {
    height: 35px;
    text-align: left;
}
#reason-table td {
    border: 1px solid #D2D2D2;
    padding: 10px 0 10px 10px;
}
#dialog{
    display: none;
}
.form-submit{
    /*margin: 5px 0 5px 0;*/
}
#TicketMessageSuperadminLoadAjaxForm th{
    padding: 0;
    line-height: 0;
}
#TicketMessageSuperadminLoadAjaxForm td{
    padding: 0;
    line-height: 0;
}
#message-table th{
    height: 35px;
    text-align: left;
}
#product-table th {
    height: 35px;
}
.ticket-message{
    width: 1158px;
    float: left;
}
.content-row{
    width: 1158px;
    float: left;
}
.table-header-options a, .table-header-repeat a{
    background: none;
}
#ticket-detail-table{
    line-height: 34px;
}
.detail-tag{
    width: 150px;
    float: left; 
}

th.line-left{
    border: none;
}
#product-table tr {
    border-bottom: 1px solid #D2D2D2;
}
#product-table td {
    border: none;
    padding: 10px 0 10px 10px;
}
#product-table th span {
    color: #FFFFFF;
    font-family: Tahoma;
    font-size: 13px;
    font-weight: bold;
    line-height: 14px;
    margin: 0 0 0 10px;
    padding: 0 10px 0 0;
}
#product-table th{
    text-align: right;
}

.reason-main_div{
    display: none;
}
.ticketReasons th{
    text-align: left !important;
}
.ticketReasons tr{
    border: none !important;
}
.ticketMessages tr{
    border: none !important;
} 
.ui-accordion-content{
    height: auto !important;
}
.reply-box p{
    text-align: center;
}

.change_status{
    background: url("/emstraining/img/../images/table/table_header_repeat.png") repeat scroll 0 0 transparent;
    border: 1px solid #503207;
    border-radius: 5px 5px 5px 5px;
    color: #5E350D !important;
    font-size: 14px;
    margin-bottom: 15px;
    padding: 8px;
    outline: medium none;
    text-decoration: none !important;
}    
.button{
    background: none repeat scroll 0 0 #000000 !important;
    border-radius: 3px 3px 3px 3px;
    padding: 7px !important;
    float: right;
    margin-right: 65px !important;
    color: #FFFFFF !important;
}
.sechedule-button{
    background: url("/emstraining/img/../images/table/table_header_repeat.png") repeat scroll 0 0 transparent;
    border-radius: 3px 3px 3px 3px;
    border: 1px solid #503207;
    color: #FFFFFF !important;
    padding: 7px !important;
    color: #000000;
    cursor: pointer;
}
#onsiteListingDialog table{
    width: 100%;
}
#onsiteListingDialog table td{
    padding: 9px;
}
#onsiteListingDialog table th{
    background: none repeat scroll 0 0 #999999;
    padding: 10px;
}
</style>